<html>
    <body>
        <input type="text" id="tower" onkeypress="jam()" />
        <input type="text" id="glass" onkeypress="jam()" />
        <input type="text" id="fill" onkeypress="jam()" />
        <input type="text" id="res" readonly="readonly" />
        <span>
        <script type="text/javascript">
            function jam() {
                var tower = document.getElementById('tower').value;
                var glass = document.getElementById('glass').value;
                var fill = document.getElementById('fill').value;
                validate(tower);
                distribute(tower, glass, fill);
            }
            function validate(a) {
                if(a > 0 && a < 21) {
                    document.getElementById('res').value = 'Invalid parameters';
                    return false;
                } else {
                    document.getElementById('res').value = 'Valid parameters';
                }
            }
            function distribute(a, b, c) {
                var con = new Array;
                var j = 0;
                while(c != 0) {
                    for(var x=0; x<a;x++) {
                        if(!con[x]) {
                            con[x] = 1;
                            c -= 1;
                            break;
                        } else {
                            if(con[x] == 1) {
                                con[x] += 1;
                                c -= 1;
                            } else {
                                alert('puno nah');
                            }
                        }
                    }
                }
                alert(con[x]);
            }
        </script>
        </span>
    </body>
</html>